#include "table.h"
/* 
Declare the KeAddSystemServiceTable. This is just a 
handle to the call function, it will be used by the function 
above to obtain the correct address of the KeServiceDescriptorShadowTable 
*/ 
__declspec(dllimport) KeAddSystemServiceTable (ULONG, ULONG, ULONG, ULONG, ULONG); 
SYS_SERVICE_TABLE * GetServiceDescriptorShadowTableAddress ()
{ 
	int i;
	unsigned char *p;
	unsigned int dwordatbyte;

	p=(unsigned char *)KeAddSystemServiceTable;

	for (i=0; i<4096; i++, p++) {
		__try {
			dwordatbyte=*(unsigned int *)p;
		}
		__except (EXCEPTION_EXECUTE_HANDLER) {
			return 0;
		}

		if (MmIsAddressValid((PVOID)dwordatbyte)) {
			if (RtlCompareMemory((PVOID)dwordatbyte, KeServiceDescriptorTable, sizeof(SYS_SERVICE_TABLE))==sizeof(SYS_SERVICE_TABLE)) {
				if ((PVOID)dwordatbyte==KeServiceDescriptorTable) {
					continue;
				}
				return (SYS_SERVICE_TABLE *)dwordatbyte;
			}
		}
	}
	return 0;

} 